import ajax from "../../utils/ajax";

//获取表单
const form = document.forms.addNote

//初始化
init()

async function init() {
    form.onsubmit = form_onsubmit;

}


function form_onsubmit(e) {
    e.preventDefault();

    if (!form.title.value || !form.content.value) {
        alert('title或者content内容不能为空')
        return;
    }

    ajax('post', '/api/addNote', {
        title: form.title.value,
        content: form.content.value
    }).then(() => {
        alert('添加成功')

        if (confirm('是否再次发布')) {
            form.reset()
        } else {
            location.replace('../../index.html')
        }

    })
}